package com.mp.ipm2020.admin.controller;

import com.mp.ipm2020.common.api.CommonResult;

import com.mp.ipm2020.common.license.AbstractServerInfos;
import com.mp.ipm2020.common.license.LinuxServerInfos;
import com.mp.ipm2020.common.license.WindowsServerInfos;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther adidasshe@mp.cn
 * <p>
 * 获取服务器信息，用于生产license授权
 */
@Api(tags = "软件许可")
@RestController
@RequestMapping("/license")
public class LicenseController {

    @ApiOperation(value = "获取服务器信息")
    @GetMapping
    public CommonResult getServerInfos() {
        String osName = System.getProperty("os.name").toLowerCase();
        AbstractServerInfos abstractServerInfos = null;
        //根据不同操作系统类型选择不同的数据获取方法
        if (osName.startsWith("windows")) {
            abstractServerInfos = new WindowsServerInfos();
        } else if (osName.startsWith("linux")) {
            abstractServerInfos = new LinuxServerInfos();
        } else {//其他服务器类型
            abstractServerInfos = new LinuxServerInfos();
        }

        return CommonResult.success(abstractServerInfos.getServerInfos());
    }
}
